package com.itheima.aimobile.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.aimobile.domain.OrderInfo;
import com.itheima.aimobile.mapper.OrderInfoMapper;
import com.itheima.aimobile.service.IOrderInfoService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements IOrderInfoService {

    @Override
    public boolean createOrder(Long userId, Long packageId) {
        // 构建订单对象
        OrderInfo order = new OrderInfo();
        order.setUserId(userId);
        order.setPackageId(packageId);
        order.setOrderTime(LocalDateTime.now()); // 当前时间为下单时间
        order.setStatus(0); // 初始状态：未生效

        // 调用Mapper插入订单
        return save(order); // save()是IService提供的方法，内部调用baseMapper.insert(order)
    }
}
